package com.playwright.util.course;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;

/**
 * @author liyanhao
 * @Date 2024-01-03 14:23
 */
public class EvaluateInBrowserContext {

    public static void main(String[] args) {
        try (Playwright playwright = Playwright.create()) {
            Browser browser = playwright.firefox().launch();
            BrowserContext context = browser.newContext();
            Page page = context.newPage();
            page.navigate("https://www.baidu.com/");
            Object dimensions = page.evaluate("() => {\n" +
                    "  return {\n" +
                    "      width: window.name,\n" +
                    "      height: window.history.scrollRestoration \n" +
//                    "      deviceScaleFactor: window.devicePixelRatio\n" +
                    "  }\n" +
                    "}");
            System.out.println(dimensions);
        }
    }
}